package ru.osu.acm.testing.listeners;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;

/**
 * User: Aleksey
 * Date: 03.03.2009
 * Time: 16:32:28
 */

public class MySessionListener implements HttpSessionListener {
    public MySessionListener() {
    }

    public void sessionCreated(HttpSessionEvent event) {
        System.out.println("Current Session created : " + event.getSession().getId() + " at " + new Date());
    }

    public void sessionDestroyed(HttpSessionEvent event) {
        HttpSession session = event.getSession();
        System.out.println("Current Session destroyed :" + session.getId() + " Logging out user");
        // Only if needed
        try {
            prepareLogoutInfoAndLogoutActiveUser(session);
        }
        catch (Exception e) {
            System.out.println("Error while logging out at session destroyed : " + e.getMessage());
        }
    }

    public void prepareLogoutInfoAndLogoutActiveUser(HttpSession httpSession) {
        // Only if needed
    }
}


